package job.job_0823;

import java.util.Arrays;

public class TwoNumSum {
    public static void main(String[] args) {
        int []arr={2,7,11,15};
        System.out.println("数组:"+ Arrays.toString(arr)+" 目标：9");
        int []answer=twoNumSum(arr,9);
        System.out.println("返回结果："+Arrays.toString(answer));

    }

    /**
     * 输入：nums = [2,7,11,15], target = 9
     * 输出：[0,1]
     * 解释：因为 nums[0] + nums[1] == 9 ，返回 [0, 1]
     */
    public static int[] twoNumSum(int[] num,int target){
        int answer[]=new int [2];
        for(int i=0;i<num.length;i++){
            if(num[i]>target){
                continue;
            }
            for(int j=i+1;j<num.length-1;j++){
                if(num[i]==(target-num[j])){
                    answer[0]=num[i];
                    answer[1]=num[j];
                }
            }
        }
        return answer;
    }
}
